package com.stox.ui.javafx.charting.widget;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.ComboBox;

import org.springframework.stereotype.Component;

import com.stox.ui.javafx.charting.model.enumeration.ChartType;
import com.stox.ui.javafx.charting.view.ChartingView;
import com.stox.ui.javafx.core.widget.wrapper.ToolBar.ToolBarChild;

@Component
public class ChartTypeComboBox extends ComboBox<ChartType> implements
		ToolBarChild {

	public ChartTypeComboBox() {
		getItems().addAll(ChartType.values());
		getSelectionModel().select(ChartType.HLC);
		valueProperty().addListener(new ChangeListener<ChartType>() {
			@Override
			public void changed(ObservableValue<? extends ChartType> arg0,
					ChartType arg1, ChartType chartType) {
				ChartingView chartingView = ChartingView.getSelectedChartingView();
				if(chartingView != null) {
					chartingView.getPrimaryChart().getFrontPlot().setChartType(chartType);
					chartingView.update();
				}
			}
		});
	}
	
	@Override
	public int getOrder() {
		return 2;
	}

}
